-- 衍生 问计
local ref_wenji = fk.CreateSkill {
    name = "mcdh_ref_wenji",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

ref_wenji:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Play and
                not table.every(player.room:getOtherPlayers(player), function(p) return (p:isNude()) end)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local to = room:askToChoosePlayers(player, {targets =table.filter(room:getOtherPlayers(player), function(p)
            return not p:isNude() end),min_num=1,max_num=1,prompt="#mcdh_ref_wenji-choose",skill_name=self.name,cancelable=true})
        if #to > 0 then
            self.cost_data = to[1]
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = self.cost_data
        local card = room:askForCard(to, 1, 1, true, self.name, false, ".", "#mcdh_ref_wenji-give::"..player.id)
        room:setPlayerMark(player, "mcdh_ref_wenji-turn", Fk:getCardById(card[1]).trueName)
        room:obtainCard(player.id, card[1], false, fk.ReasonGive)
    end,
})

ref_wenji:addEffect(fk.CardUsing,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:getMark("mcdh_ref_wenji-turn") ~= 0 and player:getMark("mcdh_ref_wenji-turn") == data.card.trueName
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        data.disresponsiveList = data.disresponsiveList or {}
        for _, p in ipairs(player.room:getOtherPlayers(player)) do
            table.insertIfNeed(data.disresponsiveList, p.id)
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_ref_wenji"] = "问计",
    [":mcdh_ref_wenji"] = "出牌阶段开始时，你可以令一名其他角色交给你一张牌，你于本回合内使用与该牌同名的牌不能被其他角色响应。",
    ["#mcdh_ref_wenji-choose"] = "问计：你可以令一名其他角色交给你一张牌",
    ["#mcdh_ref_wenji-give"] = "问计：你需交给 %dest 一张牌",
}


return ref_wenji